package com.kidfruit.controller;

import com.kidfruit.websocket.SystemWebSocketHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.socket.TextMessage;

@RestController
@RequestMapping("/rest")
public class MainRestController {

    @RequestMapping(value = "/test", method = RequestMethod.GET)
    @ResponseBody
    public String test() {
        return "test";
    }

    @RequestMapping(value = "/websocket/{message}", method = RequestMethod.GET)
    @ResponseBody
    public String websocket(@PathVariable String message) {

        systemWebSocketHandler().sendMessageToUsers(new TextMessage(message));
        return message;
    }


    @Bean
    public SystemWebSocketHandler systemWebSocketHandler() {
        return new SystemWebSocketHandler();
    }
}